from django.core.management.base import BaseCommand
from user.models import User
from django.contrib.auth.hashers import check_password


class Command(BaseCommand):
    help = '检查测试用户信息'

    def handle(self, *args, **options):
        test_phone = '13800138000'
        user = User.objects.filter(phone=test_phone).first()

        if user:
            self.stdout.write(f"找到用户: {user.username}")
            self.stdout.write(f"手机号: {user.phone}")
            self.stdout.write(f"密码哈希: {user.password_hash}")
            self.stdout.write(f"状态: {user.status}")
            self.stdout.write(f"角色: {user.role}")
            
            # 检查密码
            is_valid = check_password('123456', user.password_hash)
            self.stdout.write(f"密码验证: {is_valid}")
            
            # 尝试明文密码比较
            is_plaintext = user.password_hash == '123456'
            self.stdout.write(f"明文密码比较: {is_plaintext}")
        else:
            self.stdout.write("用户不存在")
            
        # 列出所有用户
        self.stdout.write("\n所有用户:")
        for u in User.objects.all()[:5]:
            self.stdout.write(f"- {u.username} ({u.phone})")
